package com.jcbase.job;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import org.apache.log4j.Logger;

public class TaskManage {

	private static Logger log = Logger.getLogger(TaskManage.class);
	
	public static  void addJob(TimerTask Task,long time){
		Timer timer = new Timer();
		//每天凌晨执行
		  Calendar calendar = Calendar.getInstance();  
		  calendar.add(Calendar.DATE, 1); // 控制时  
	      calendar.set(Calendar.HOUR_OF_DAY, 0); // 控制时  
	      calendar.set(Calendar.MINUTE, 0);       // 控制分  
	      calendar.set(Calendar.SECOND, 0);       // 控制秒  
	      Date date = calendar.getTime();  
	      SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	      log.info("首次执行时间为 "+sim.format(date));
		timer.scheduleAtFixedRate(Task, date, time);
	}
	
	
}
